package wiki.tools.vidition.droid;

import java.util.ArrayList;
import wiki.tools.vidition.droid.util.bean.RSSItem;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ShowRSSAdapter extends BaseAdapter {
	private LayoutInflater layoutInflater;
	private ArrayList<RSSItem>rss;
	
	public ShowRSSAdapter(Context c) {
		layoutInflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	
	public int getCount() {
		return rss.size();
	}

	public RSSItem getItem(int position) {
		return rss.get(position);
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		if(null == convertView) {
			convertView = layoutInflater.inflate(R.layout.showrssadatper, parent, false);
		}
		TextView title = (TextView) convertView.findViewById(R.id.showrssadapter_title);
		TextView desc = (TextView) convertView.findViewById(R.id.showrssadapter_desc);
		ImageView photo = (ImageView) convertView.findViewById(R.id.showrssadapter_photo);
		photo.setVisibility(View.GONE);
		
		RSSItem item = getItem(position);
		
		title.setText(item.text);
		desc.setText(item.description);
		
		if(null != item.photo) {
			photo.setVisibility(View.VISIBLE);
			photo.setImageBitmap(item.photo);
		}
		return convertView;
	}

	public void setData(ArrayList<RSSItem>rss) {
		this.rss = rss;
		notifyDataSetChanged();
	}
}